package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type User struct {
	ID        string    `gorm:"primaryKey; type:varchar(255)" json:"id"`
	Username  string    `gorm:"type:varchar(255)" json:"username"`
	Password  string    `gorm:"type:varchar(255)" json:"password"`
	Nickname  string    `gorm:"type:varchar(255)" json:"nickname"`
	CreatedAt time.Time `gorm:"type:timestamp" json:"created_at"`
	UpdatedAt time.Time `gorm:"type:timestamp" json:"updated_at"`
	Email     string    `gorm:"type:varchar(255);" json:"email"`
	Phone     string    `gorm:"type:varchar(255);" json:"phone"`
	State     int       `gorm:"type:int; default:1" json:"state"`
	Avatar    string    `gorm:"type:varchar(255);" json:"avatar"`
}

func (game_user *User) TableName() string {
	return "chat_user"
}

func (game_user *User) BeforeCreate(tx *gorm.DB) error {
	game_user.ID = uuid.NewString()
	game_user.CreatedAt = time.Now()
	return nil
}
func (game_user *User) BeforeUpdate(tx *gorm.DB) error {
	game_user.UpdatedAt = time.Now()
	return nil
}
